package com.func.boom.enums;

/**
 * @author Yulei
 * @date 2020-08-19 15:20:50
 * @desc 枚举
 */
public enum ResultEnums {

    SUCCESS(200, "请求成功"),
    SUCCESS_SAVE(201, "添加成功"),
    SUCCESS_UPDATE(202, "修改成功"),
    SUCCESS_DELETE(203, "删除成功"),
    FAILURE_SAVE(204, "添加失败"),
    FAILURE_UPDATE(205, "修改失败"),
    FAILURE_DELETE(206, "删除失败"),
    SUCCESS_QUERY(207, "查询成功"),
    ERROR_401(401, "token无效"),
    ERROR(500, "系统异常，请稍后重试"),

    ERROR_10010(10010, "网关服务异常，请稍后重试"),

    ERROR_20100(20100, "该手机号已被注册"),
    ERROR_20200(20200, "用户账号密码不正确"),
    ERROR_20300(20300, "该手机号未注册"),
    ERROR_20400(20400, "验证码不正确"),
    ;

    public static final Integer SUCCESS_REQUEST = 200;
    public static final Integer ERROR_REQUEST = 500;

    /**
     * 返回码
     */
    private int code;

    /**
     * 返回消息
     */
    private String message;

    ResultEnums(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据返回码查询返回实体类
     * @param code
     * @return
     */
    public static ResultEnums getResultEnums(int code) {
        for (ResultEnums rb : ResultEnums.values()) {
            if (rb.getCode() == code) {
                return rb;
            }
        }
        return null;
    }

    /**
     * 根据返回码查询返回消息体
     * @param code
     * @return
     */
    public static String getMessage(int code) {
        for (ResultEnums rb : ResultEnums.values()) {
            if (rb.getCode() == code) {
                return rb.getMessage();
            }
        }

        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


}
